<?php

namespace App\Transformers;

use App\Models\Type;
use League\Fractal\TransformerAbstract;

class TypeTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['products'];
    public function transform(Type $type)
    {
        return [
            'id' => $type->id,
            'name' => $type->name,
            'ordernum' => $type->ordernum,
            'description' => $type->description,
        ];
    }

    public function includeProducts(Type $type)
    {
        $products = $type->products;

        return $this->collection($products, new ProductTransformer());
    }

}